package org.microservice.system.listenter;

import lombok.extern.slf4j.Slf4j;
import org.microservice.common.entity.SysZuulRoute;
import org.microservice.common.util.constant.CacheConstant;
import org.microservice.common.util.constant.MqQueueConstant;
import org.microservice.redis.util.RedisService;
import org.microservice.system.service.SysZuulRouteService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: 齐丹枫
 * Date: 2018/7/24
 * Time: 8:37
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Component
@Slf4j
@RabbitListener(queues = MqQueueConstant.ROUTE_CONFIG_CHANGE)
public class ZuulRouteReciveListener {

    @Autowired
    private SysZuulRouteService sysZuulRouteService;

    @Autowired
    private RedisService redisService;

    @RabbitHandler
    public void receive(String s){
        List<SysZuulRoute> zuulRoutes = sysZuulRouteService.getBydelFlag(false);

        redisService.set(CacheConstant.ZUUL_ROUTE_KEY,zuulRoutes);
        log.info("更新路由到缓存中");

    }

}
